package test.twlTheme;

import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.DisplayMode;
import org.lwjgl.opengl.GL11;

import twl.global.input.GlobalGUI;
import twl.global.input.GlobalLwjglInput;

import de.matthiasmann.twl.GUI;
import de.matthiasmann.twl.ToggleButton;
import de.matthiasmann.twl.Widget;
import de.matthiasmann.twl.renderer.lwjgl.LWJGLRenderer;
import de.matthiasmann.twl.theme.ThemeManager;

public class TwlTheme {
	
	GlobalGUI globalGUI;
	Widget rootPane;
	
	public TwlTheme(){
		try {
            Display.setDisplayMode(new DisplayMode(800, 600));
            Display.create();
            Display.setTitle("TWL Chat Demo");
            Display.setVSyncEnabled(true);
            
            globalGUI = new GlobalGUI();
            rootPane = new Widget();
            rootPane.setTheme("");
            
            

            LWJGLRenderer renderer = new LWJGLRenderer();
            ThemeManager theme = ThemeManager.createThemeManager(
                    TwlTheme.class.getResource("/test/twlTheme/ButtonTheme.xml"), renderer);
            GUI gui = new GUI(rootPane, renderer, new GlobalLwjglInput(globalGUI));        
            gui.applyTheme(theme);
            
            layout();

            while(!Display.isCloseRequested()) {
                GL11.glClear(GL11.GL_COLOR_BUFFER_BIT);

                gui.update();

                Display.update();
            }

            gui.destroy();
        } catch (Exception e) {
            e.printStackTrace();
        }
        Display.destroy();
	}
	
	private void layout() {
		Widget panel = new Widget();
		panel.setTheme("borderPanel");
		rootPane.add(panel);
		panel.setSize(300, 300);
		
		ToggleButton button = new ToggleButton("Hello");
		button.setTheme("borderButton");
		//button.setDrawingMode(GWidget.DRAW_WITH_THEME);
		panel.add(button);
		button.setPosition(200, 200);
		button.setSize(50, 50);
	}

	public static void main(String[] args) {
        new TwlTheme();
    }

}
